import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';



@Injectable()
export class TokenService {
  loginFlag = false;
  private source = new BehaviorSubject<boolean>(this.loginFlag);

  public login() {
    this.loginFlag = true;
    this.updateLoginFlag(this.loginFlag);
  }

  public logout() {
    this.loginFlag = false;
    this.updateLoginFlag(this.loginFlag);
  }

  private updateLoginFlag(flag: boolean) {
    this.source.next(flag);
  }

  getFlag(): boolean {
    return this.loginFlag;
  }
}
